<template>
  <div>
    <el-dialog
      title="共建课程"
      :visible.sync="dialogVisible"
      width="600px"
      @closed="resetForm('form')"
    >
      <div>
        <el-form ref="form" :rules="rules" :model="form" label-width="80px">
          <el-form-item label="申请描述" prop="des">
            <el-input
              type="textarea"
              :rows="2"
              placeholder="请输入申请描述"
              v-model="form.des"
            >
            </el-input>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button  type="custom" v-preventReClick  @click="submitForm('form')">提 交</el-button>
        <el-button @click="dialogVisible = false">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { sysCourseTeamAdd } from "@/api/admin/courseLibrary/sysCourseTeam.js";
import Bus from "@/utils/bus.js";
export default {
  data() {
    return {
      dialogVisible: false,
      form: {
        auditStatus: "1",
        orderBy: "10",
        des: "",
        courseId: "",
        courseOriginator: "",
        userId: this.$store.getters.userId,
      },
      rules: {
        des: [{ required: true, message: "请输入申请描述", trigger: "blur" }],
      },
    };
  },
  mounted() {
    Bus.$on("showDialogCourseBuild", (v) => {
      if (!this.form.userId) {
        this.loginTip();
        return;
      }
      this.form.courseId = v.id;
      this.form.courseOriginator = v.createBy;
      this.dialogVisible = true;
    });
  },
  beforeDestroy() {
    Bus.$off("showDialogCourseBuild");
  },
  methods: {
    submitForm(form) {
      this.$refs[form].validate((valid) => {
        if (valid) {
          this.add();
        }
      });
    },
    //申请共建
    add() {
      sysCourseTeamAdd(this.form).then((res) => {
        this.$parent.getList();
        this.dialogVisible = false;
        this.$message({
          message: "操作成功",
          type: "success",
        });
      });
    },
    //重置表单
    resetForm(form) {
      this.$refs[form].resetFields();
      this.form.des = "";
      this.form.auditStatus = "1";
    },
  },
};
</script>